//
//  DefiniteViewController.m
//  ShangChengMoBan
//
//  Created by 军 on 16/8/25.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "DefiniteViewController.h"
#import "RedoteTableViewCell.h"
@interface DefiniteViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation DefiniteViewController
{
    RWScrollView * _table;
    NSMutableArray * _arr;
    int _page;
}
- (void)viewDidLoad {
     _page = 1;
    [super viewDidLoad];
    [self drawNavWithTitle:@"积分明细" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    [self drawBackButton];
   _table = [[RWScrollView alloc]initWithFrame:CGRectMake(0,70, KScreenWidth,KScreenHeight-70)];
    [_table addHeaderWithTarget:self action:@selector(headRefresh)];
    [_table headerBeginRefreshing];
    [_table addFooterWithTarget:self action:@selector(footerRefresh)];
   _table.delegate = self;
    _table.dataSource = self;
    _table.rowHeight = 50;
     _table.separatorStyle = UITableViewCellSelectionStyleNone;
    [_table registerClass:[RedoteTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_table];
}
-(void)headRefresh{
    _page = 1;
    [self requestData:1];
}
-(void)footerRefresh{
    _page ++;
    [self requestData:0];
}

#pragma mark 积分明细请求
-(void)requestData:(int)first{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setObject:@"10" forKey:@"pageSize"];
    [requestDic setObject:[NSString stringWithFormat:@"%d",_page] forKey:@"pageNum"];
    [requestDic setObject:[self defaultLoadUserName] forKey:@"userName"];
    
    [NetWorking NEWjieKouQingQiu:JJSC_findMyExchangeGoods ANDIP:IP And:requestDic anBlock:^(NSDictionary *dic, NSError *error) {
        [_table headerEndRefreshing];
        [_table footerEndRefreshing];
        if (!error) {
            
            if ([dic[Code] intValue] == 200) {
                if (first == 1) {
                    _arr = [[NSMutableArray alloc]init];
                    
                }
                [_arr addObjectsFromArray:dic[Response][@"goods"]] ;
                [_table reloadData];
            }
        }
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * shuJu = _arr[indexPath.row];
    RedoteTableViewCell  * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.title.text = shuJu[@"goods"][@"goodsName"];
    cell.num.text = [NSString stringWithFormat:@"%@",shuJu[@"exchangeIntegral"]];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
